﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Revit;
using YRevitJig;

namespace YArchitech.HVAC.LevelIndependentTag
{
	public class CreatePipeLevelLinesJin : XUiJigBase
	{
		public XYZ StartPoint { get; set; }

		public XYZ TagLocation
		{
			get
			{
				return this.tagLocation;
			}
		}

		public CreatePipeLevelLinesJin(UIDocument uiDoc, Autodesk.Revit.DB.View view, YJKLine hyLine, bool single, bool triangle, bool hasLeadWire) : base(uiDoc)
		{
			this.view = view;
			this.single = single;
			this.triangle = triangle;
			this.hasLeadWire = hasLeadWire;
			this.hyLine = hyLine;
		}

		public override void Draw(PaintEventArgs paintEventArgs)
		{
			base.Draw(paintEventArgs);
			if (!this.m_ptCur.IsEmpty && paintEventArgs != null)
			{
				try
				{
					this.resultLines.Clear();
					MarkPipeLevelUtility.leaderLines.Clear();
					XYZ xyz = base.Client2Revit(this.m_ptCur);
					XYZ location = new XYZ(xyz.X, xyz.Y, this.StartPoint.Z);
					if (this.single)
					{
						if (this.triangle)
						{
							this.resultLines = MarkPipeLevelUtility.DrawTriangle(this.view, this.StartPoint, location, ref this.tagLocation, ref this.directionVector, this.hasLeadWire, this.hyLine, this.movingDistance);
						}
						else
						{
							this.resultLines = MarkPipeLevelUtility.DrawLeadWire(this.view, this.StartPoint, location, ref this.tagLocation, ref this.directionVector, this.hyLine);
						}
					}
					else if (this.triangle)
					{
						this.resultLines = MarkPipeLevelUtility.DrawMutilSelectTriangle(this.view, this.StartPoint, location, ref this.tagLocation, ref this.directionVector, this.hyLine, this.mutilDirection);
					}
					else
					{
						this.resultLines = MarkPipeLevelUtility.DrawMutilSelectLeadWire(this.view, this.StartPoint, location, ref this.tagLocation, ref this.directionVector, this.hyLine, this.mutilDirection, this.selectedElements);
					}
					XGraphics g = new XGraphics(paintEventArgs.Graphics, base.JigPen);
					foreach (Line curve in this.resultLines)
					{
						new XLine2D(base.Revit2Client(curve.GetEndPoint(0)), base.Revit2Client(curve.GetEndPoint(1))).Draw(g);
					}
				}
				catch (Exception ex)
				{
					ex.ToString();
				}
			}
		}

		private XYZ tagLocation = new XYZ();

		public DirectionVector directionVector = new DirectionVector();

		public XYZ mutilDirection = new XYZ();

		public double movingDistance;

		public List<Element> selectedElements = new List<Element>();

		private YJKLine hyLine;

		private Autodesk.Revit.DB.View view;

		public List<Line> resultLines = new List<Line>();

		private bool single;

		private bool triangle;

		private bool hasLeadWire;
	}
}
